package thread_learn2;

class Func1{
    public int count;
    public void add(){
        synchronized(this){
            count++;
        }
        count++;
    }
}
public class demon2 {
    public static void main(String[] args) throws InterruptedException {
        Func func=new Func();
        Thread thread=new Thread(()->{
            for (int i = 0; i < 5000; i++) {
                synchronized (func){
                    func.add();
                }

            }
        });
        Thread thread1=new Thread(()->{
            for (int i = 0; i < 5000; i++) {
                synchronized (func){
                    func.add();
                }
            }
        });
        thread.start();
        thread1.start();
        thread1.join();
        thread.join();
        System.out.println(func.count);

    }
}
